/**
 * Copyright 2015 - 2016 KeepSafe Software, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.getkeepsafe.relinker.elf;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
 * Function description
 * class Program64Header
 */
public class Program32Header extends Elf.ProgramHeader {
    /**
     * Constructor Section64Header
     *
     * @param parser ElfParser
     * @param header Elf.Header
     * @param index integer
     */
    public Program32Header(final ElfParser parser, final Elf.Header header, final long index) {
        final ByteBuffer buffer = ByteBuffer.allocate(4);
        buffer.order(header.mIsBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);

        final long baseOffset = header.mPhoff + (index * header.mPhentsize);
        type = parser.readWord(buffer, baseOffset);
        offset = parser.readWord(buffer, baseOffset + Constants.OFFSET_VAL_32);
        vaddr = parser.readWord(buffer, baseOffset + Constants.VADDR_VAL_32);
        memsz = parser.readWord(buffer, baseOffset + Constants.MEMSZ_VAL_32);
    }
}
